<?php

declare(strict_types=1);

namespace App\Job;

use Hyperf\AsyncQueue\Job;
use App\Model\Order;
use Hyperf\DbConnection\Db;

class NormalOrderExampleJob extends Job
{
    public $params;
    
    /**
     * 任务执行失败后的重试次数，即最大执行次数为 $maxAttempts+1 次
     */
    protected int $maxAttempts = 2;

    public function __construct($params)
    {
        $this->params = $params;
    }

    public function handle()
    {
//        order插入一条记录
		$order = new Order();
		$order->order_id = $this->params[1];
		$order->user_id = $this->params[2];
		$order->money = $this->params[3];
		$order->save();

//		orderGood批量插入记录
		Db::table('order_good')->insert($this->params[0]);
    }
}
